﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HaumDisplay
{
    public class HaumImage
    {
        /// <summary>
        /// 图像
        /// </summary>
        public Bitmap bmp;

        /// <summary>
        /// 角度
        /// </summary>
        public ushort rotate;

        /// <summary>
        /// 像素
        /// </summary>
        public int pixel;

        /// <summary>
        /// 像素格式
        /// </summary>
        public PixelFormat pixelFormat;

        /// <summary>
        /// 位大小
        /// </summary>
        public short bitDepth;

        /// <summary>
        /// 文件名
        /// </summary>
        public string fileName;

        /// <summary>
        /// 图像类型
        /// </summary>
        public ImageFormat imageFormat;

        /// <summary>
        /// 文件全路径
        /// </summary>
        public string fullPath;

        /// <summary>
        /// 时间
        /// </summary>
        public DateTime time;

        /// <summary>
        /// 空间大小 MB
        /// </summary>
        public double size;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="image">图像</param>
        /// <param name="path">路径 默认""</param>
        public HaumImage(Image image, string path = "")
        {
            //图像
            this.bmp = image as Bitmap;
            //像素
            this.pixel = image.Width * image.Height;
            //像素格式
            this.pixelFormat = image.PixelFormat;
            //位深度
            switch (image.PixelFormat)
            {
                case PixelFormat.Format1bppIndexed: this.bitDepth = 1; break;
                case PixelFormat.Format4bppIndexed: this.bitDepth = 4; break;
                case PixelFormat.Format8bppIndexed: this.bitDepth = 8; break;
                case PixelFormat.Format16bppRgb555:
                case PixelFormat.Format16bppRgb565:
                case PixelFormat.Format16bppGrayScale: this.bitDepth = 16; break;
                case PixelFormat.Format24bppRgb: this.bitDepth = 24; break;
                case PixelFormat.Format32bppRgb:
                case PixelFormat.Format32bppArgb:
                case PixelFormat.Format32bppPArgb: this.bitDepth = 32; break;
                case PixelFormat.Format48bppRgb: this.bitDepth = 48; break;
                case PixelFormat.Format64bppArgb:
                case PixelFormat.Format64bppPArgb: this.bitDepth = 64; break;
                default: this.bitDepth = 0; break;
            }

            if (path == "")
            {
                this.fileName = "NAN";
                //图像全路径
                this.fullPath = "NAN";
            }
            else
            {
                //获取不带扩展名的文件名
                this.fileName = Path.GetFileNameWithoutExtension(path);
                //图像全路径
                this.fullPath = path;
            }
            //获取图像类型
            if (image.RawFormat.Equals(ImageFormat.Jpeg))this.imageFormat = ImageFormat.Jpeg;
            else if (image.RawFormat.Equals(ImageFormat.Png)) this.imageFormat = ImageFormat.Png;
            else if (image.RawFormat.Equals(ImageFormat.Bmp)) this.imageFormat = ImageFormat.Bmp;
            else if (image.RawFormat.Equals(ImageFormat.Gif)) this.imageFormat = ImageFormat.Gif;
            else if (image.RawFormat.Equals(ImageFormat.Tiff)) this.imageFormat = ImageFormat.Tiff;
            else { this.imageFormat = null; }
            //时间
            this.time = DateTime.Now;
            //图像大小
            this.size = this.bmp.Width * this.bmp.Height * this.bitDepth / 8 / 1024.0 / 1024.0;
        }
    }
}
